package com.common;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Static {
	public static String getImgStr(String htmlStr){         
        StringBuilder pics = new StringBuilder();
        String imageurl="";
         
        String regEx_img = "<img.*?src=\"(.*?)\"";
        Pattern pat = Pattern.compile(regEx_img);
        Matcher mat = pat.matcher(htmlStr);
        while (mat.find()) {
       	 pics.append(mat.group(1));
    	 pics.append("|");
        }
        
        imageurl=pics.toString();
        if(pics.length()>0){
        	if(imageurl.indexOf("|", (pics.length()-2))>-1){
        		imageurl=imageurl.substring(0,pics.length()-1);
        	}
        }
        return imageurl;
     }
	public static byte[] InputStreamToByte(InputStream iStrm) throws IOException {
	    ByteArrayOutputStream bytestream = new ByteArrayOutputStream();
	    int ch;
	    while ((ch = iStrm.read()) != -1)
	    {
	       bytestream.write(ch);
	    }
	    byte imgdata[]=bytestream.toByteArray();
	    bytestream.close();
	    return imgdata;
    }
	//求几天后的时间
	public static String populate(String str,double days) throws Exception{
		int num = (int) days;

		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");		
		Date dd = format.parse(str);
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(dd);
		calendar.add(Calendar.DAY_OF_MONTH, num);
		String T3 = format.format(calendar.getTime());
		return T3;
	}
	//求几个月后的时间
	public static String popmouth(String str,double days) throws Exception{
		int num = (int) days;

		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM");		
		Date dd = format.parse(str);
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(dd);
		calendar.add(Calendar.MONTH, num);
		String T3 = format.format(calendar.getTime());
		return T3;
	}
	public static boolean isNumeric1(String str){
		Pattern pattern = Pattern.compile("[-+]?[0-9]+\\.{0,8}[0-9]{0,20}$");
		return pattern.matcher(str).matches();
	}
	public static void main(String[] args) {
		  try {
			  String curtime = new SimpleDateFormat("dd").format(new Date());
			System.out.println(curtime);

		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}	  
	 }
}
